<?php
namespace Modules\Admin\Model\Data;

use \Modules\Admin\Model\Dao\Db\Acl\Group as DaoDbAclGroup;
use \Modules\Admin\Model\Dao\Db\Acl\User as DaoDbAclUser;
use \Modules\Admin\Model\Dao\Db\Acl\All as DaoDbAclAll;
use \Modules\Admin\Model\Dao\Db\User\Group as DaoDbUserGroup;

/**
 * 权限管理
 */
class Acl {
    /**
     * 获取用户所属组所有权限
     * @param integer $uid 用户id
     * @return array
     */
    public function getUserGroupAclList($uid) {
        $gid = (new DaoDbUserGroup())->getGidByUid($uid);
        $group_acl_list = array();
        if ($gid) {
            $group_acl_list = (new DaoDbAclGroup())->getList($gid);
        }
        return $group_acl_list;
    }

    /**
     * 获取用户所有权限信息
     * @param integer $uid 用户id
     * @return array
     */
    public function getUserAclList($uid){
        $user_acl = (new DaoDbAclUser())->getList($uid);
        return $user_acl;
    }

    /**
     * 获取组所有权限信息
     * @param integer|array $gid 组id
     * @return array
     */
    public function getGroupAclList($gid){
        $group_acl = (new DaoDbAclGroup())->getList($gid);
        return $group_acl;
    }

    /**
     * 获取全局权限权限
     * @return array
     */
    public function getAllAclList(){
        $all_acl = (new DaoDbAclAll())->getList();
        return $all_acl;
    }

    /**
     * 新增用户权限
     * @param array $data 权限数据
     * @return int
     */
    public function addUserAcl($data) {
        return (new DaoDbAclUser())->add($data);
    }

    /**
     * 删除用户权限
     * @param array $data 权限数据
     * @return boolean
     */
    public function delUserAcl($data) {
        return (new DaoDbAclUser())->del($data);
    }

    /**
     * 新增用户组权限
     * @param array $data 权限数据
     * @return int
     */
    public function addGroupAcl($data) {
        return (new DaoDbAclGroup())->add($data);
    }

    /**
     * 删除用户组权限
     * @param array $data 权限数据
     * @return boolean
     */
    public function delGroupAcl($data) {
        return (new DaoDbAclGroup())->del($data);
    }

    /**
     * 添加全局权限
     * @param $data
     * @return bool
     */
    public function addAcl($data){
        return (new DaoDbAclAll())->add($data);
    }

    /**
     * 删除全局权限
     * @param $data
     * @return bool
     */
    public function delAcl($data){
        return (new DaoDbAclAll())->del($data);
    }

}